package com.ruoyi.workOrder.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.ruoyi.workOrder.mapper.WorkOrderMapper;
import com.ruoyi.workOrder.domain.WorkOrder;
import com.ruoyi.workOrder.service.IWorkOrderService;

/**
 * 运维工单Service业务层处理
 * 
 * @author likui
 * @date 2023-11-16
 */
@Service
public class WorkOrderServiceImpl implements IWorkOrderService {
    @Resource
    private WorkOrderMapper workOrderMapper;

    /**
     * 查询运维工单
     * 
     * @param workId 运维工单主键
     * @return 运维工单
     */
    @Override
    public WorkOrder selectWorkOrderByWorkId(Long workId) {
        return workOrderMapper.selectWorkOrderByWorkId(workId);
    }

    /**
     * 查询运维工单列表
     * 
     * @param workOrder 运维工单
     * @return 运维工单
     */
    @Override
    public List<WorkOrder> selectWorkOrderList(WorkOrder workOrder) {
        return workOrderMapper.selectWorkOrderList(workOrder);
    }

    /**
     * 新增运维工单
     * 
     * @param workOrder 运维工单
     * @return 结果
     */
    @Override
    public int insertWorkOrder(WorkOrder workOrder) {
        workOrder.setCreateTime(DateUtils.getNowDate());
        return workOrderMapper.insertWorkOrder(workOrder);
    }

    /**
     * 修改运维工单
     * 
     * @param workOrder 运维工单
     * @return 结果
     */
    @Override
    public int updateWorkOrder(WorkOrder workOrder) {
        workOrder.setUpdateTime(DateUtils.getNowDate());
        return workOrderMapper.updateWorkOrder(workOrder);
    }

    /**
     * 批量删除运维工单
     * 
     * @param workIds 需要删除的运维工单主键
     * @return 结果
     */
    @Override
    public int deleteWorkOrderByWorkIds(Long[] workIds) {
        return workOrderMapper.deleteWorkOrderByWorkIds(workIds);
    }

    /**
     * 删除运维工单信息
     * 
     * @param workId 运维工单主键
     * @return 结果
     */
    @Override
    public int deleteWorkOrderByWorkId(Long workId) {
        return workOrderMapper.deleteWorkOrderByWorkId(workId);
    }

    /**
     * 导入运维工单数据
     *
     * @param workOrderList 工单列表
     * @param isUpdateSupport 是否更新支持，如果已存在，则进行更新数据
     * @param operName 操作用户
     * @return 结果
     */

    @Override
    public String importWorkOrder( List<WorkOrder> workOrderList, Boolean isUpdateSupport, String operName ) {
        if ( workOrderList.size( ) == 0 ) {
            return "导入的数据为空";
        }
        try {
            for ( WorkOrder workOrder : workOrderList ) {
                workOrder.setUpdateTime( DateUtils.getNowDate( ) );
                workOrder.setIsDelete( "1" );
                workOrderMapper.insertWorkOrder( workOrder );
            }
            return "导入成功";
        } catch ( Exception e ) {
            e.printStackTrace( );
            return "导入异常";
        }
    }
}
